import p from "./p";

export function objectToCode(prefix: string, obj: Record<string, any>): string[] {
  const entries = Object.entries(obj);

  const objectContent: string[] = [];
  entries.forEach(([key, value]) => {
    if (typeof value === 'string') {
      objectContent.push(`${key}: ${value},`);
    } else if (Array.isArray(value)) {
      objectContent.push(`${key}: {`, ...p(value), `},`);
    } else {
      objectContent.push(`${key}: {`, ...p(objectToCode('', value).slice(1, -1)), `},`);
    }
  });

  return [
    prefix + '{',
    ...p(objectContent),
    '}'
  ]
}